home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / IDE scripts / Widget demos / WidgetTest.py < prev   
Encoding:
Text File  |  2000-06-23  |  2.2 KB  |  86 lines

  1. import W
  2.  
  3. # define some callbacks
  4. def callback():
  5.     window.close()
  6.  
  7. def checkcallback(value):
  8.     print "hit the checkbox", value
  9.  
  10. def radiocallback(value):
  11.     print "hit radiobutton #3", value
  12.  
  13. def scrollcallback(value):
  14.     widget = window.hbar
  15.     if value == "+":
  16.         widget.set(widget.get() - 1)
  17.     elif value == "-":
  18.         widget.set(widget.get() + 1)
  19.     elif value == "++":
  20.         widget.set(widget.get() - 10)
  21.     elif value == "--":
  22.         widget.set(widget.get() + 10)
  23.     else:   # in thumb
  24.         widget.set(value)
  25.     print "scroll...", widget.get()
  26.  
  27. def textcallback():
  28.     window.et3.set(window.et1.get())
  29.  
  30. def cancel():
  31.     import EasyDialogs
  32.     EasyDialogs.Message("Cancel!")
  33.  
  34. # make a non-sizable window
  35. #window = W.Window((200, 300), "Fixed Size")
  36.  
  37. #  make a sizable window
  38. window = W.Window((200, 300), "Variable Size!", minsize = (200, 300))
  39.  
  40. # make some edit text widgets
  41. window.et1 = W.EditText((10, 10, 110, 110), "Hallo!", textcallback)
  42. window.et2 = W.EditText((130, 40, 60, 30), "one!")
  43. window.et3 = W.EditText((130, 80, -10, 40), "two?")
  44.  
  45. # a button
  46. window.button = W.Button((-70, 10, 60, 16), "Close", callback)
  47.  
  48. # a checkbox
  49. window.ch = W.CheckBox((10, 130, 160, 16), "Check (command §)", checkcallback)
  50.  
  51. # set of radio buttons (should become easier/nicer)
  52. thebuttons = []
  53. window.r1 = W.RadioButton((10, 150, 180, 16), "Radio 1 (cmd 1)", thebuttons)
  54. window.r2 = W.RadioButton((10, 170, 180, 16), "Radio 2 (cmd 2)", thebuttons)
  55. window.r3 = W.RadioButton((10, 190, 180, 16), "Radio 3 (cmd 3)", thebuttons, radiocallback)
  56. window.r1.set(1)
  57.  
  58. # a normal button
  59. window.cancelbutton = W.Button((10, 220, 60, 16), "Cancel", cancel)
  60.  
  61. # a scrollbar
  62. window.hbar = W.Scrollbar((-1, -15, -14, 16), scrollcallback, max = 100)
  63.  
  64. # some static text
  65. window.static = W.TextBox((10, 260, 110, 16), "Schtatic")
  66.  
  67. # bind some keystrokes to functions
  68. window.bind('cmd§', window.ch.push)
  69. window.bind('cmd1', window.r1.push)
  70. window.bind('cmd2', window.r2.push)
  71. window.bind('cmd3', window.r3.push)
  72. window.bind('cmdw', window.button.push)
  73. window.bind('cmd.', window.cancelbutton.push)
  74.  
  75. window.setdefaultbutton(window.button)
  76. # open the window
  77. window.open()
  78.  
  79. if 0:
  80.     import time
  81.     for i in range(20):
  82.         window.et2.set(`i`)
  83.         #window.et2.SetPort()
  84.         #window.et2.draw()
  85.         time.sleep(0.1)
  86.